//
// Created by lujun on 19-6-28.
//
// This contains SIN_COS , clarke, inv_clarke, park, inv_park and pid
// each one has it's own function.
// All function can be found in main function.
// If you don't want to use it, then comment it.
#include "../common.h"
#include "riscv_common_tables.h"
#include "riscv_const_structs.h"
#include "riscv_math.h"
#include <stdint.h>

#include "../HelperFunctions/math_helper.c"
#include "../HelperFunctions/ref_helper.c"

#include <stdio.h>
#define DELTAF32 (0.05f)
#define DELTAQ31 (63)
#define DELTAQ15 (1)
#define DELTAQ7 (1)

int test_flag_error = 0;

uint32_t fftSize = 1024;
uint32_t ifftFlag = 0;
uint32_t doBitReverse = 1;

static int DSP_rfft_q31(void)
{
    /* clang-format off */
    float32_t rfft_testinput_f32_50hz_200Hz[1024] = {
    0,0.744219717332704,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186548,0.221231742082474,-0.0600499921067857,-1.11022302462516e-16,0.399903088302664,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186548,4.44089209850063e-16,-0.497066016555608,-0.642039521920206,-0.431350787252243,-3.67394039744206e-16,0.431350787252243,0.642039521920206,0.497066016555607,-1.22124532708767e-15,-0.707106781186549,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-1.00000000000000,-0.399903088302665,-3.33066907387547e-16,0.0600499921067852,-0.221231742082476,-0.707106781186550,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332705,-1.22464679914735e-15,0.744219717332707,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186549,0.221231742082475,-0.0600499921067854,8.88178419700125e-16,0.399903088302667,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186545,1.33226762955019e-15,-0.497066016555608,-0.642039521920206,-0.431350787252245,-1.10218211923262e-15,0.431350787252243,0.642039521920206,0.497066016555606,1.55431223447522e-15,-0.707106781186550,-1.39680224666743,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999995,-0.399903088302669,-7.77156117237610e-16,0.0600499921067867,-0.221231742082473,-0.707106781186549,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332702,-2.44929359829471e-15,0.744219717332706,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186546,0.221231742082476,-0.0600499921067846,-7.77156117237610e-16,0.399903088302660,0.999999999999998,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186546,-4.88498130835069e-15,-0.497066016555607,-0.642039521920206,-0.431350787252242,3.49210031947972e-15,0.431350787252243,0.642039521920206,0.497066016555610,2.55351295663786e-15,-0.707106781186549,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999996,-0.399903088302658,-9.99200722162641e-16,0.0600499921067855,-0.221231742082477,-0.707106781186554,-1.17557050458494,-1.40504701603470,-1.26007351067011,-0.744219717332711,-3.67394039744206e-15,0.744219717332705,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186547,0.221231742082472,-0.0600499921067872,-1.22124532708767e-15,0.399903088302665,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186539,-1.09912079437891e-14,-0.497066016555607,-0.642039521920206,-0.431350787252238,8.08638275819206e-15,0.431350787252234,0.642039521920205,0.497066016555611,3.55271367880050e-15,-0.707106781186548,-1.39680224666741,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999997,-0.399903088302671,-1.44328993201270e-15,0.0600499921067857,-0.221231742082476,-0.707106781186553,-1.17557050458494,-1.40504701603470,-1.26007351067010,-0.744219717332697,-4.89858719658941e-15,0.744219717332704,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186548,0.221231742082472,-0.0600499921067871,3.88578058618805e-15,0.399903088302676,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048352,1.39680224666743,0.707106781186557,4.44089209850063e-15,-0.497066016555606,-0.642039521920207,-0.431350787252247,-3.30654635769785e-15,0.431350787252242,0.642039521920206,0.497066016555611,4.55191440096314e-15,-0.707106781186546,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999998,-0.399903088302660,3.66373598126302e-15,0.0600499921067860,-0.221231742082476,-0.707106781186552,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332698,1.16403343982657e-14,0.744219717332718,1.26007351067010,1.40504701603470,1.17557050458496,0.707106781186561,0.221231742082482,-0.0600499921067840,-1.99840144432528e-15,0.399903088302663,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048353,1.39680224666743,0.707106781186558,5.44009282066327e-15,-0.497066016555606,-0.642039521920206,-0.431350787252239,6.61680659921524e-15,0.431350787252249,0.642039521920207,0.497066016555612,5.55111512312578e-15,-0.707106781186545,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288760,-0.999999999999984,-0.399903088302648,-2.10942374678780e-15,0.0600499921067861,-0.221231742082475,-0.707106781186552,-1.17557050458493,-1.40504701603470,-1.26007351067011,-0.744219717332714,-7.34788079488412e-15,0.744219717332702,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186538,0.221231742082483,-0.0600499921067839,-2.33146835171283e-15,0.399903088302663,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666741,0.707106781186559,6.32827124036339e-15,-0.497066016555605,-0.642039521920206,-0.431350787252240,5.88201851972683e-15,0.431350787252249,0.642039521920207,0.497066016555597,-2.22044604925031e-14,-0.707106781186544,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288760,-0.999999999999985,-0.399903088302649,8.43769498715119e-15,0.0600499921067808,-0.221231742082475,-0.707106781186551,-1.17557050458495,-1.40504701603470,-1.26007351067009,-0.744219717332685,2.69546091939735e-14,0.744219717332731,1.26007351067009,1.40504701603470,1.17557050458496,0.707106781186562,0.221231742082484,-0.0600499921067836,-2.77555756156289e-15,0.399903088302662,1,1.57547359288759,1.90211303259030,1.84206304048353,1.39680224666743,0.707106781186560,7.32747196252603e-15,-0.497066016555605,-0.642039521920206,-0.431350787252240,5.14723044023841e-15,0.431350787252232,0.642039521920205,0.497066016555613,7.54951656745106e-15,-0.707106781186543,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288760,-0.999999999999986,-0.399903088302674,-2.99760216648792e-15,0.0600499921067865,-0.221231742082474,-0.707106781186550,-1.17557050458495,-1.40504701603470,-1.26007351067009,-0.744219717332686,-9.79717439317883e-15,0.744219717332699,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186540,0.221231742082465,-0.0600499921067890,7.88258347483861e-15,0.399903088302685,0.999999999999999,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666741,0.707106781186528,-2.04281036531029e-14,-0.497066016555619,-0.642039521920204,-0.431350787252241,4.41244236075000e-15,0.431350787252248,0.642039521920207,0.497066016555598,8.43769498715119e-15,-0.707106781186542,-1.39680224666742,-1.84206304048351,-1.90211303259031,-1.57547359288763,-1.00000000000002,-0.399903088302675,-3.33066907387547e-15,0.0600499921067867,-0.221231742082473,-0.707106781186549,-1.17557050458493,-1.40504701603470,-1.26007351067011,-0.744219717332717,-1.10218211923262e-14,0.744219717332698,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186540,0.221231742082485,-0.0600499921067832,-3.44169137633799e-15,0.399903088302660,0.999999999999998,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666741,0.707106781186563,9.32587340685132e-15,-0.497066016555604,-0.642039521920206,-0.431350787252242,3.67765428126159e-15,0.431350787252247,0.642039521920207,0.497066016555599,-1.93178806284777e-14,-0.707106781186541,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288760,-0.999999999999988,-0.399903088302652,7.32747196252603e-15,0.0600499921067813,-0.221231742082492,-0.707106781186548,-1.17557050458495,-1.40504701603470,-1.26007351067009,-0.744219717332688,2.32806687965315e-14,0.744219717332727,1.26007351067012,1.40504701603470,1.17557050458494,0.707106781186541,0.221231742082467,-0.0600499921067831,-1.47659662275146e-14,0.399903088302659,0.999999999999969,1.57547359288761,1.90211303259030,1.84206304048352,1.39680224666744,0.707106781186530,1.02140518265514e-14,-0.497066016555588,-0.642039521920206,-0.431350787252258,2.94286620177318e-15,0.431350787252230,0.642039521920207,0.497066016555614,-1.83186799063151e-14,-0.707106781186540,-1.39680224666739,-1.84206304048352,-1.90211303259031,-1.57547359288761,-1.00000000000002,-0.399903088302653,-4.10782519111308e-15,0.0600499921067815,-0.221231742082472,-0.707106781186571,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332719,2.20560219973841e-14,0.744219717332696,1.26007351067011,1.40504701603470,1.17557050458493,0.707106781186542,0.221231742082486,-0.0600499921067884,-4.21884749357560e-15,0.399903088302682,0.999999999999996,1.57547359288763,1.90211303259031,1.84206304048351,1.39680224666741,0.707106781186565,-1.75415237890775e-14,-0.497066016555603,-0.642039521920204,-0.431350787252243,2.35243601950878e-14,0.431350787252246,0.642039521920209,0.497066016555600,1.15463194561016e-14,-0.707106781186572,-1.39680224666742,-1.84206304048353,-1.90211303259031,-1.57547359288763,-0.999999999999990,-0.399903088302677,-1.54321000422897e-14,0.0600499921067873,-0.221231742082452,-0.707106781186547,-1.17557050458493,-1.40504701603470,-1.26007351067011,-0.744219717332690,-1.46957615897682e-14,0.744219717332665,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186566,0.221231742082468,-0.0600499921067826,6.32827124036339e-15,0.399903088302658,1.00000000000002,1.57547359288761,1.90211303259030,1.84206304048352,1.39680224666744,0.707106781186533,1.23234755733392e-14,-0.497066016555617,-0.642039521920207,-0.431350787252227,1.47329004279635e-15,0.431350787252229,0.642039521920207,0.497066016555615,-1.62092561595273e-14,-0.707106781186537,-1.39680224666744,-1.84206304048352,-1.90211303259030,-1.57547359288761,-1.00000000000002,-0.399903088302654};
    uint16_t i, j;
    q31_t rfft_testinput_q31_50hz_200Hz[1024] = {0}, rfft_testinput_q31_50hz_200Hz_ref[1024] = {0};
    /* clang-format on */
    riscv_float_to_q31(rfft_testinput_f32_50hz_200Hz,
                     rfft_testinput_q31_50hz_200Hz, 1024);
    riscv_float_to_q31(rfft_testinput_f32_50hz_200Hz,
                     rfft_testinput_q31_50hz_200Hz_ref, 1024);
    riscv_rfft_instance_q31 SS;
    fftSize = 512;
    ifftFlag = 0;
    doBitReverse = 1;
    riscv_rfft_init_q31(&SS, fftSize, ifftFlag, doBitReverse);
    q31_t q31_testOutput[1024], q31_testOutput_ref[1024];
    BENCH_START(riscv_rfft_q31);
    riscv_rfft_q31(&SS, rfft_testinput_q31_50hz_200Hz, q31_testOutput);
    BENCH_END(riscv_rfft_q31);
    riscv_rfft_init_q31(&SS, fftSize, ifftFlag, doBitReverse);
    ref_rfft_q31(&SS, rfft_testinput_q31_50hz_200Hz_ref, q31_testOutput_ref);
    q31_t resault, resault_ref;
    uint32_t index, index_ref;
    riscv_shift_q31(q31_testOutput, 8, q31_testOutput, fftSize);
    riscv_shift_q31(q31_testOutput_ref, 8, q31_testOutput_ref, fftSize);
    riscv_max_q31(q31_testOutput, 512, &resault, &index);
    riscv_max_q31(q31_testOutput_ref, 512, &resault_ref, &index_ref);
    if (index != index_ref) {
        BENCH_ERROR(riscv_rfft_q31);
        printf("expect: %d, actual: %d\n", index_ref, index);
        test_flag_error = 1;
    }
    BENCH_STATUS(riscv_rfft_q31);
}
static int DSP_rfft_q15(void)
{
    /* clang-format off */
    float32_t rfft_testinput_f32_50hz_200Hz[1024] = {
    0,0.744219717332704,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186548,0.221231742082474,-0.0600499921067857,-1.11022302462516e-16,0.399903088302664,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186548,4.44089209850063e-16,-0.497066016555608,-0.642039521920206,-0.431350787252243,-3.67394039744206e-16,0.431350787252243,0.642039521920206,0.497066016555607,-1.22124532708767e-15,-0.707106781186549,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-1.00000000000000,-0.399903088302665,-3.33066907387547e-16,0.0600499921067852,-0.221231742082476,-0.707106781186550,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332705,-1.22464679914735e-15,0.744219717332707,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186549,0.221231742082475,-0.0600499921067854,8.88178419700125e-16,0.399903088302667,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186545,1.33226762955019e-15,-0.497066016555608,-0.642039521920206,-0.431350787252245,-1.10218211923262e-15,0.431350787252243,0.642039521920206,0.497066016555606,1.55431223447522e-15,-0.707106781186550,-1.39680224666743,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999995,-0.399903088302669,-7.77156117237610e-16,0.0600499921067867,-0.221231742082473,-0.707106781186549,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332702,-2.44929359829471e-15,0.744219717332706,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186546,0.221231742082476,-0.0600499921067846,-7.77156117237610e-16,0.399903088302660,0.999999999999998,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186546,-4.88498130835069e-15,-0.497066016555607,-0.642039521920206,-0.431350787252242,3.49210031947972e-15,0.431350787252243,0.642039521920206,0.497066016555610,2.55351295663786e-15,-0.707106781186549,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999996,-0.399903088302658,-9.99200722162641e-16,0.0600499921067855,-0.221231742082477,-0.707106781186554,-1.17557050458494,-1.40504701603470,-1.26007351067011,-0.744219717332711,-3.67394039744206e-15,0.744219717332705,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186547,0.221231742082472,-0.0600499921067872,-1.22124532708767e-15,0.399903088302665,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048352,1.39680224666742,0.707106781186539,-1.09912079437891e-14,-0.497066016555607,-0.642039521920206,-0.431350787252238,8.08638275819206e-15,0.431350787252234,0.642039521920205,0.497066016555611,3.55271367880050e-15,-0.707106781186548,-1.39680224666741,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999997,-0.399903088302671,-1.44328993201270e-15,0.0600499921067857,-0.221231742082476,-0.707106781186553,-1.17557050458494,-1.40504701603470,-1.26007351067010,-0.744219717332697,-4.89858719658941e-15,0.744219717332704,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186548,0.221231742082472,-0.0600499921067871,3.88578058618805e-15,0.399903088302676,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048352,1.39680224666743,0.707106781186557,4.44089209850063e-15,-0.497066016555606,-0.642039521920207,-0.431350787252247,-3.30654635769785e-15,0.431350787252242,0.642039521920206,0.497066016555611,4.55191440096314e-15,-0.707106781186546,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288761,-0.999999999999998,-0.399903088302660,3.66373598126302e-15,0.0600499921067860,-0.221231742082476,-0.707106781186552,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332698,1.16403343982657e-14,0.744219717332718,1.26007351067010,1.40504701603470,1.17557050458496,0.707106781186561,0.221231742082482,-0.0600499921067840,-1.99840144432528e-15,0.399903088302663,1.00000000000000,1.57547359288762,1.90211303259031,1.84206304048353,1.39680224666743,0.707106781186558,5.44009282066327e-15,-0.497066016555606,-0.642039521920206,-0.431350787252239,6.61680659921524e-15,0.431350787252249,0.642039521920207,0.497066016555612,5.55111512312578e-15,-0.707106781186545,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288760,-0.999999999999984,-0.399903088302648,-2.10942374678780e-15,0.0600499921067861,-0.221231742082475,-0.707106781186552,-1.17557050458493,-1.40504701603470,-1.26007351067011,-0.744219717332714,-7.34788079488412e-15,0.744219717332702,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186538,0.221231742082483,-0.0600499921067839,-2.33146835171283e-15,0.399903088302663,1.00000000000000,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666741,0.707106781186559,6.32827124036339e-15,-0.497066016555605,-0.642039521920206,-0.431350787252240,5.88201851972683e-15,0.431350787252249,0.642039521920207,0.497066016555597,-2.22044604925031e-14,-0.707106781186544,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288760,-0.999999999999985,-0.399903088302649,8.43769498715119e-15,0.0600499921067808,-0.221231742082475,-0.707106781186551,-1.17557050458495,-1.40504701603470,-1.26007351067009,-0.744219717332685,2.69546091939735e-14,0.744219717332731,1.26007351067009,1.40504701603470,1.17557050458496,0.707106781186562,0.221231742082484,-0.0600499921067836,-2.77555756156289e-15,0.399903088302662,1,1.57547359288759,1.90211303259030,1.84206304048353,1.39680224666743,0.707106781186560,7.32747196252603e-15,-0.497066016555605,-0.642039521920206,-0.431350787252240,5.14723044023841e-15,0.431350787252232,0.642039521920205,0.497066016555613,7.54951656745106e-15,-0.707106781186543,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288760,-0.999999999999986,-0.399903088302674,-2.99760216648792e-15,0.0600499921067865,-0.221231742082474,-0.707106781186550,-1.17557050458495,-1.40504701603470,-1.26007351067009,-0.744219717332686,-9.79717439317883e-15,0.744219717332699,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186540,0.221231742082465,-0.0600499921067890,7.88258347483861e-15,0.399903088302685,0.999999999999999,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666741,0.707106781186528,-2.04281036531029e-14,-0.497066016555619,-0.642039521920204,-0.431350787252241,4.41244236075000e-15,0.431350787252248,0.642039521920207,0.497066016555598,8.43769498715119e-15,-0.707106781186542,-1.39680224666742,-1.84206304048351,-1.90211303259031,-1.57547359288763,-1.00000000000002,-0.399903088302675,-3.33066907387547e-15,0.0600499921067867,-0.221231742082473,-0.707106781186549,-1.17557050458493,-1.40504701603470,-1.26007351067011,-0.744219717332717,-1.10218211923262e-14,0.744219717332698,1.26007351067010,1.40504701603470,1.17557050458494,0.707106781186540,0.221231742082485,-0.0600499921067832,-3.44169137633799e-15,0.399903088302660,0.999999999999998,1.57547359288761,1.90211303259031,1.84206304048352,1.39680224666741,0.707106781186563,9.32587340685132e-15,-0.497066016555604,-0.642039521920206,-0.431350787252242,3.67765428126159e-15,0.431350787252247,0.642039521920207,0.497066016555599,-1.93178806284777e-14,-0.707106781186541,-1.39680224666742,-1.84206304048352,-1.90211303259031,-1.57547359288760,-0.999999999999988,-0.399903088302652,7.32747196252603e-15,0.0600499921067813,-0.221231742082492,-0.707106781186548,-1.17557050458495,-1.40504701603470,-1.26007351067009,-0.744219717332688,2.32806687965315e-14,0.744219717332727,1.26007351067012,1.40504701603470,1.17557050458494,0.707106781186541,0.221231742082467,-0.0600499921067831,-1.47659662275146e-14,0.399903088302659,0.999999999999969,1.57547359288761,1.90211303259030,1.84206304048352,1.39680224666744,0.707106781186530,1.02140518265514e-14,-0.497066016555588,-0.642039521920206,-0.431350787252258,2.94286620177318e-15,0.431350787252230,0.642039521920207,0.497066016555614,-1.83186799063151e-14,-0.707106781186540,-1.39680224666739,-1.84206304048352,-1.90211303259031,-1.57547359288761,-1.00000000000002,-0.399903088302653,-4.10782519111308e-15,0.0600499921067815,-0.221231742082472,-0.707106781186571,-1.17557050458495,-1.40504701603470,-1.26007351067010,-0.744219717332719,2.20560219973841e-14,0.744219717332696,1.26007351067011,1.40504701603470,1.17557050458493,0.707106781186542,0.221231742082486,-0.0600499921067884,-4.21884749357560e-15,0.399903088302682,0.999999999999996,1.57547359288763,1.90211303259031,1.84206304048351,1.39680224666741,0.707106781186565,-1.75415237890775e-14,-0.497066016555603,-0.642039521920204,-0.431350787252243,2.35243601950878e-14,0.431350787252246,0.642039521920209,0.497066016555600,1.15463194561016e-14,-0.707106781186572,-1.39680224666742,-1.84206304048353,-1.90211303259031,-1.57547359288763,-0.999999999999990,-0.399903088302677,-1.54321000422897e-14,0.0600499921067873,-0.221231742082452,-0.707106781186547,-1.17557050458493,-1.40504701603470,-1.26007351067011,-0.744219717332690,-1.46957615897682e-14,0.744219717332665,1.26007351067010,1.40504701603470,1.17557050458495,0.707106781186566,0.221231742082468,-0.0600499921067826,6.32827124036339e-15,0.399903088302658,1.00000000000002,1.57547359288761,1.90211303259030,1.84206304048352,1.39680224666744,0.707106781186533,1.23234755733392e-14,-0.497066016555617,-0.642039521920207,-0.431350787252227,1.47329004279635e-15,0.431350787252229,0.642039521920207,0.497066016555615,-1.62092561595273e-14,-0.707106781186537,-1.39680224666744,-1.84206304048352,-1.90211303259030,-1.57547359288761,-1.00000000000002,-0.399903088302654};
    uint16_t i, j;
    q15_t rfft_testinput_q15_50hz_200Hz[1024] = {0}, rfft_testinput_q15_50hz_200Hz_ref[1024] = {0};
    /* clang-format on */
    riscv_float_to_q15(rfft_testinput_f32_50hz_200Hz,
                     rfft_testinput_q15_50hz_200Hz, 1024);
    riscv_float_to_q15(rfft_testinput_f32_50hz_200Hz,
                     rfft_testinput_q15_50hz_200Hz_ref, 1024);
    riscv_rfft_instance_q15 SS;
    fftSize = 512;
    ifftFlag = 0;
    doBitReverse = 1;
    riscv_rfft_init_q15(&SS, fftSize, ifftFlag, doBitReverse);
    q15_t q15_testOutput[1024], q15_testOutput_ref[1024];
    BENCH_START(riscv_rfft_q15);
    riscv_rfft_q15(&SS, rfft_testinput_q15_50hz_200Hz, q15_testOutput);
    BENCH_END(riscv_rfft_q15);
    riscv_rfft_init_q15(&SS, fftSize, ifftFlag, doBitReverse);
    ref_rfft_q15(&SS, rfft_testinput_q15_50hz_200Hz_ref, q15_testOutput_ref);
    q15_t resault, resault_ref;
    riscv_shift_q15(q15_testOutput, 6, q15_testOutput, fftSize);
    riscv_shift_q15(q15_testOutput_ref, 6, q15_testOutput_ref, fftSize);
    uint32_t index, index_ref;
    riscv_max_q15(q15_testOutput, fftSize, &resault, &index);
    riscv_max_q15(q15_testOutput_ref, fftSize, &resault_ref, &index_ref);
    if (index != index_ref) {
        BENCH_ERROR(riscv_rfft_q15);
        printf("expect: %d, actual: %d\n", index_ref, index);
        test_flag_error = 1;
    }
    BENCH_STATUS(riscv_rfft_q15);
}

int main()
{
    BENCH_INIT;
    DSP_rfft_q31();
    DSP_rfft_q15();
    BENCH_FINISH;
    if (test_flag_error) {
        printf("test error apprears, please recheck.\n");
        return 1;
    } else {
        printf("all test are passed. Well done!\n");
    }
    return 0;
}
